package excercise;

public class EX07_Q35 {

	// 거스름 돈 구하기
	public static void main(String[] args) {
		int pay = 32190;
		int money = 100000;
		int charge = money - pay;
		int W50000 = 0, W10000 = 0, W5000 = 0,
			 W1000 = 0, W500 = 0, W100 = 0, W50, 
			 W10 = 0;
		
		System.out.println( "계산할 금액 : " + pay );
		System.out.println( "지급액 : " + money );
		System.out.println( "잔돈 : " + charge );
		
		W50000 = charge / 50000;
		charge = charge % 50000;
		
		W10000 = charge / 10000;
		charge = charge % 10000;
		
		W5000 = charge / 5000;
		charge = charge % 5000;
		
		W1000 = charge / 1000;
		charge = charge % 1000;
		
		W500 = charge / 500;
		charge = charge % 500;
		
		W100 = charge / 100;
		charge = charge % 100;
		
		W50 = charge / 50;
		charge = charge % 50;
		
		W10 = charge / 10;
				
		System.out.println( "5만원권 : " + W50000 );
		System.out.println( "1만원권 : " + W10000 );
		System.out.println( "5천원권 : " + W5000 );
		System.out.println( "1천원권 : " + W1000 );
		System.out.println( "5백원권 : " + W500 );
		System.out.println( "1백원권 : " + W100 );
		System.out.println( "5십원권 : " + W50 );
		System.out.println( "1십원권 : " + W10 );
		
		// 반복문, 배열을 이용한 잔돈 처리
		int[] charges = { 0,0,0,0,0,0,0,0,0 };
		int[] moneys = { 0, 50000, 10000, 5000, 1000, 
								 500, 100, 50, 10 };
		
		charge = money - pay;
		for(int i = 1; i <= 8; ++i ) {
			charges[ i ] = charge / moneys[ i ];
			charge = charge % moneys[ i ];
			System.out.println( moneys[ i ] + "/" + charges[i] );
		}
		
	}

}




